const encryption = {
  // 加密
  encode(json) {
    const str = JSON.stringify(json);
    return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
      (match, p1) => String.fromCharCode(`0x${p1}`)));
  },
  // 解密
  decode(str) {
    // Going backwards: from bytestream, to percent-encoding, to original string.
    const st = decodeURIComponent(atob(str).split('').map((c) => `%${(`00${c.charCodeAt(0).toString(16)}`).slice(-2)}`).join(''));
    return JSON.parse(st);
  }
};
export default encryption;
